var xyTools = {
  // 取min-max之间的随机整数
  getRandomInteger(min, max) {
    return Math.floor(Math.random() * (max - min + 1)) + min;
  },
  // 获取userId
  userId() {
    return uni.getStorageSync('userId');
  },
  // 是否为空
  isEmpty(obj) {
    if(typeof(obj) == 'string') {
      return obj == 'undefined' || obj == 'null' || obj.trim() == ''
    }else if (typeof(obj) == 'undefined') {
      return obj == undefined
    }else if (typeof(obj) == 'object') {
      if(obj == null) {
        return true
      }
      return Object.keys(obj).length ? false : true
    }else if (typeof(obj) == 'boolean') {
      return obj
    }    return false
  },
  // 移除对象中没有值的key
  removeEmptyKeys(obj) {
    return Object.keys(obj).reduce((acc, key) => {
      if(this.isEmpty(obj[key])) {
        delete obj[key];
      }
    }, {});
  },
  safeAreaBottom() {
    const info = uni.getSystemInfoSync();
    return (info.safeAreaInsets.bottom ? info.safeAreaInsets.bottom : 10) + 'px';
  },
  // 处理富文本字符串,用于处理uni原生组件<rich-text>图片中间有间隙的问题
  handleRichTextStyle(richTexStr) {
    return richTexStr.replace(/\<p/gi, '<p style="display: flex;flex-direction: column;"').replace(/\<img/gi, '<img style="width:100%;height:auto;margin:0rpx;padding:0rpx;vertical-align:bottom;"')
  },
  // 微信支付
  wxPay(params, callback) {
		uni.requestPayment({
			provider: 'wxpay',
			timeStamp: params.timeStamp,
			nonceStr: params.nonceStr,
			package: params.package,
			signType: params.signType,
			paySign: params.paySign,
			success: (res) => {
				callback(res,null)
			},
			fail: (err) => {
				callback(null,err)
			}
		});
	}
  
}

export default xyTools